<?php include 'session.php'?>
<?php include 'header.php'?>

<?php
if (isset($_POST['submit'])) {
	$cid = $_SESSION['cid'];
	$index = $_POST['ship_method'];
	$resultShippingMethods = $soap->call($session_id, "cart_shipping.list", array($cid));
	$code_selected = $resultShippingMethods[$index]['code'];
	$addShippingMethod = $soap->call($session_id, "cart_shipping.method", array($cid, $code_selected));
	$price_ship = number_format($resultShippingMethods[$index]['price'], 2, '.', ',');
	$_SESSION['shipPrice'] = $price_ship;
	header("location: payment.php");
}
?>

<div id="Main">
    <div id="Content">
		<header class="row">
			<h2>Shipping Method</h2>
		</header>
		
		<div class="row">
<?php
$cid = $_SESSION['cid'];
$resultShippingMethods = $soap->call($session_id, "cart_shipping.list", array($cid));
$num = sizeof($resultShippingMethods);
//echo print_r( $resultShippingMethods );
echo 		'<form action="" method="post">';
for ($i = 0; $i < $num; $i++) {
$code = $resultShippingMethods[$i]['code'];
$carrier_title = $resultShippingMethods[$i]['carrier_title'];
$method_title = $resultShippingMethods[$i]['method_title'];
$price = number_format($resultShippingMethods[$i]['price'], 2, '.', ',');
$message = $carrier_title . " - " . $method_title . " - $" . $price;
			echo "<input type=\"radio\" name=\"ship_method\" value=\"$i\"/>$message<br/>";
}
echo <<< HERE
				<br/>
				<ul class="buttons">
					<li style="float:left"><input type="button" value="Back" onclick="javascript:history.go(-1);" class="button-secondary" /></li>
					<li style="float:left; margin-left:10px"><input type="submit" value="Next" name="submit" class="button-secondary" /></li>
				</ul>
				<br/>
			</form>
HERE;
?>
		</div>
	</div>

<?php include 'footer.php'?>